<!--
Copyright 2013 The Polymer Authors. All rights reserved.
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
<polymer-element name="polymer-ui-theme-aware" attributes="theme">
  <script>
    PolymerUI = { 
      findTheme: function() {
        var p = this, theme;
        while (p && !theme) {
          theme = p.getAttribute && p.getAttribute('theme');
          p = p.parentNode || p.host;
        }
        this.theme = theme;
      }
    };
    Polymer('polymer-ui-theme-aware', {
      inserted: function() {
        if (!this.theme) {
          this.findTheme();
        }
      },
      findTheme: PolymerUI.findTheme,
      themeChanged: function(old) {
        this.classList.switch(old, this.theme);
      }
    });
  </script>
</polymer-element>
